var template = function () {
    var c = {}, x = Object.prototype.hasOwnProperty, r = Array.prototype.indexOf, s = Array.prototype.some, t = Array.prototype.filter, u = Array.prototype.map, n = {}; c.type = function (a) { var b, d = /\{\s*\[native\s*code\]\s*\}/i; null === a ? b = "null" : "undefined" === typeof a ? b = "undefined" : (b = Object.prototype.toString.call(a).match(/\w+/g)[1].toLowerCase(), "object" === b && d.test(a + "") && (b = "function")); return b }; c.trim = function (a) { return (a + "").replace(/^[\s\u00A0]+|[\s\u00A0]+$/g, "") }; c.extend = function () {
        var a =
            arguments.callee, b, d; "object" !== c.type(arguments[0]) ? (b = 1, d = !!arguments[0]) : (b = 0, d = !1); var e = arguments[b] || {}; b = [].slice.call(arguments, b + 1); for (var k, h; b.length;)if (k = b.shift(), "object" === c.type(k)) {
            var f, g; for (g in k) if (f = k[g], "object" === c.type(f)) if (f == window || f == document || "childNodes" in f && "nextSibling" in f && "nodeType" in f) { if (d || !(g in e)) e[g] = f } else if (f.jquery && /^[\d\.]+$/.test(f.jquery)) e[g] = f; else {
                h = c.type(e[g]); if (!(g in e) || "undefined" === h || "null" === h || d && ("string" === h || "number" === h || "bool" ===
                    h)) e[g] = {}; "object" === c.type(e[g]) && a(d, e[g], f)
            } else if (d || !(g in e)) e[g] = f
        } return e
    }; var p = c.each = function (a, b, d) { if (null != a) if ([].forEach && a.forEach === [].forEach) a.forEach(b, d); else if (a.length === +a.length) for (var e = 0, k = a.length; e < k && b.call(d, a[e], e, a) !== n; e++); else for (e in a) if (c.has(a, e) && b.call(d, a[e], e, a) === n) break }; c.has = function (a, b) { return x.call(a, b) }; c.identity = function (a) { return a }; var v = c.some = c.any = function (a, b, d) {
        b || (b = c.identity); var e = !1; if (null == a) return e; if (s && a.some === s) return a.some(b,
            d); p(a, function (a, c, f) { if (e || (e = b.call(d, a, c, f))) return n }); return !!e
    }; c.find = c.detect = function (a, b, d) { var e; v(a, function (a, c, f) { if (b.call(d, a, c, f)) return e = a, !0 }); return e }; c.contains = c.include = function (a, b) { return null == a ? !1 : r && a.indexOf === r ? -1 != a.indexOf(b) : v(a, function (a) { return a === b }) }; c.filter = c.select = function (a, b, d) { var c = []; if (null == a) return c; if (t && a.filter === t) return a.filter(b, d); p(a, function (a, h, f) { b.call(d, a, h, f) && (c[c.length] = a) }); return c }; c.map = c.collect = function (a, b, c) {
        var e = [];
        if (null == a) return e; if (u && a.map === u) return a.map(b, c); p(a, function (a, h, f) { e[e.length] = b.call(c, a, h, f) }); return e
    }; c.invert = function (a) { var b = {}, d; for (d in a) c.has(a, d) && (b[a[d]] = d); return b }; c.keys = Object.keys || function (a) { if (a !== Object(a)) throw new TypeError("Invalid object"); var b = [], d; for (d in a) c.has(a, d) && (b[b.length] = d); return b }; c.values = function (a) { var b = [], d; for (d in a) c.has(a, d) && b.push(a[d]); return b }; c.random = function (a, b) { null == b && (b = a, a = 0); return a + Math.floor(Math.random() * (b - a + 1)) };
    var l = { escape: { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#x27;", "/": "&#x2F;" } }; l.unescape = c.invert(l.escape); var y = { escape: RegExp("[" + c.keys(l.escape).join("") + "]", "g"), unescape: RegExp("(" + c.keys(l.unescape).join("|") + ")", "g") }; c.each(["escape", "unescape"], function (a) { c[a] = function (b) { return null == b ? "" : ("" + b).replace(y[a], function (b) { return l[a][b] }) } }); var w = { evaluate: /{{([\s\S]+?)}}/g, interpolate: /{{=([\s\S]+?)}}/g, escape: /{{-([\s\S]+?)}}/g }, q = /(.)^/, z = {
        "'": "'", "\\": "\\", "\r": "r", "\n": "n",
        "\t": "t", "\u2028": "u2028", "\u2029": "u2029"
    }, A = /\\|'|\r|\n|\t|\u2028|\u2029/g, m = function (a, b, d) {
        var e; d = c.extend(!0, {}, w, d); var k = RegExp([(d.escape || q).source, (d.interpolate || q).source, (d.evaluate || q).source].join("|") + "|$", "g"), h = 0, f = "__p+='"; a.replace(k, function (b, c, d, e, g) { f += a.slice(h, g).replace(A, function (a) { return "\\" + z[a] }); c && (f += "'+\n((__t=(" + c + "))==null?'':util.escape(__t))+\n'"); d && (f += "'+\n((__t=(" + d + "))==null?'':__t)+\n'"); e && (f += "';\n" + e + "\n__p+='"); h = g + b.length; return b }); f += "';\n"; d.variable ||
        (f = "with(obj||{}){\n" + f + "}\n"); f = "var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n" + f + "return __p;\n"; try { e = new Function(d.variable || "obj", "util", f) } catch (g) { throw g.source = f, g; } if (b) return e(b, c); b = function (a) { return e.call(this, a, c) }; b.source = "function(" + (d.variable || "obj") + "){\n" + f + "}"; return b
    }; m.util = c; m.entities = l; m.settings = w; return m
}.call(this);
var TEMP = { tpl: function (t, e) { e = e || /\<\!--\s*#+\s*([\w\.]+)\s*#+\s*--\>([\w\W]*?)\<\!--\s*#+\s*end\s*#+\s*--\>/gi, t = t.toString() || "", e.exec(""); for (var r = {}, n = null; n = e.exec(t);)for (var i = n[1].split("."), l = r; i.length;) { var a = i.shift(); a in l || (l[a] = {}), i.length || (l[a] = n[2].replace(/^[\s\u00A0]+|[\s\u00A0]+$/g, "")), l = l[a] } return r } }; TEMP.templatify = function () { var n = function () { return "" }, i = Object.prototype.toString; return function (t) { var e = n; if ("string" == typeof t) e = template(t); else if ("[object Object]" === i.call(t)) for (var r in e = {}, t) e[r] = TEMP.templatify(t[r]); return e } }.call(this); var TEMPFY = function (t) { return TEMP.templatify(TEMP.tpl(t)) };//@import(common/lib/template.js)

; void function () {


    var tmpl = TEMPFY("<!-- ## wrap ## -->\r\n{{ if(max > 1){ }}\r\n<div class=\"pager-wrap J-async-pager-wrap\">\r\n    <div class=\"page-num\">\r\n        <a href=\"javascript:void(0)\" class=\"page-prev J-pager-item {{ if(pageNum == 1){ }}page-disabled{{ } }} {{if(simple){}}pager-simple{{}}}\" data-current=\"{{=pageNum-1}}\" rel=\"nofollow\"><i class=\"vd-icon icon-left\"></i>{{if(!simple){}}上一页{{}}}</a>\r\n        <a href=\"javascript:void(0)\" class=\"{{ if(pageNum == 1){ }}page-current{{ } }} J-pager-item\" data-current=\"1\" rel=\"nofollow\">1</a>\r\n\r\n        {{ if(max > 9 && pageNum > 5){ }}\r\n        <strong class=\"omit\">...</strong>\r\n        {{ } }}\r\n\r\n        {{ for(var i = range[0]; i <= range[1]; i++){ }}\r\n        <a href=\"javascript:void(0)\" class=\"J-pager-item {{ if(pageNum == i){ }}page-current{{ } }}\" data-current=\"{{=i}}\" rel=\"nofollow\">{{=i}}</a>\r\n        {{ } }}\r\n\r\n        {{ if(max > 9 && pageNum < max - 4){ }}\r\n        <strong class=\"omit\">...</strong>\r\n        {{ } }}\r\n        <a href=\"javascript:void(0)\" class=\"{{ if(pageNum == max){ }}page-current{{ } }} J-pager-item\" data-current=\"{{=max}}\" rel=\"nofollow\">{{=max}}</a>\r\n        <a href=\"javascript:void(0)\" class=\"page-next J-pager-item {{ if(pageNum == max){ }}page-disabled{{ } }} {{if(simple){}}pager-simple{{}}}\" data-current=\"{{=pageNum+1}}\" rel=\"nofollow\">{{if(!simple){}}下一页{{}}}<i class=\"vd-icon icon-right\"></i></a>\r\n        {{ if(needJump){ }}\r\n        <div class=\"page-jump\">\r\n            <span class=\"page-jump-txt\">到第：</span>\r\n            <input type=\"text\" class=\"page-input J-pager-input\">\r\n            <a href=\"javascript:void(0)\" class=\"page-jump-btn J-pager-jump\" data-link=\"javascript:void(0)\">确定</a>\r\n        </div>\r\n        {{}}}\r\n    </div>\r\n</div>\r\n{{ } }}\r\n<!-- ## end ## -->");

    var defaults = {
        el: null,
        pageNum: 1,
        total: 91,
        pageSize: 10,
        needJump: true,
        callback: null,
        simple: false
    };

    var Pager = function (config) {
        this.config = $.extend({}, defaults, config);
        this.__init();
        return this;
    }

    Pager.prototype = {
        constructor: 'Pager',
        __init: function () {
            this.$wrap = $(this.config.el);

            var config = this.config;
            this.max = Math.ceil(config.total / config.pageSize);
            var params = $.extend({}, { max: this.max }, config);
            params.range = this.__getRange(params);
            this.$wrap.append(tmpl.wrap(params));
            this.__bindEvent();
        },
        __bindEvent: function () {
            var _this = this;

            this.$wrap.on('click', '.J-pager-item', function () {
                var isDisabled = ($(this).hasClass('page-disabled') || $(this).hasClass('page-current'));
                var pageNum = $(this).data('current');

                if (!isDisabled) {
                    _this.reset({ pageNum: pageNum });

                    _this.config.callback && _this.config.callback(pageNum);
                }
            })

            this.$wrap.on('click', '.J-pager-jump', function () {
                var $input = $('.J-pager-input', _this.$wrap);
                var pageNum = $input.val();

                if (!pageNum) {
                    $input.focus();
                    return false;
                }

                if (!/^\d*$/.test(pageNum)) {
                    $input.val('').focus();
                } else {
                    var num = parseInt(pageNum);
                    pageNum = num < 1 ? 1 : (num > _this.max ? _this.max : num);
                    $input.val('');
                    _this.reset({ pageNum: parseInt(pageNum) });

                    _this.config.callback && _this.config.callback(pageNum);
                }
            })
        },
        __getRange: function (params) {
            var cur = params.pageNum;
            var max = params.max;
            var range = [];

            if (max > 9) {
                if (cur < 5) {
                    range = [2, 8];
                } else if (cur > max - 4) {
                    range = [max - 7, max - 1];
                } else {
                    range = [cur - 3, cur + 3];
                }
            } else {
                range = [2, max - 1]
                console.log(max)
            }

            return range;
        },
        reset: function (params) {
            var newParams = $.extend({}, this.config, params);
            this.max = newParams.max = Math.ceil(newParams.total / newParams.pageSize);
            newParams.range = this.__getRange(newParams);

            this.$wrap.empty().append(tmpl.wrap(newParams));
        }
    }

    window.Pager = Pager;


}.call(this);//@import(common/assets/pager/pager.js);

; void function () {


    var tmpl = TEMPFY("<!-- ## wrap ## -->\r\n<div class=\"vd-dlg-wrap J-vd-dlg-wrap\">\r\n    <div class=\"vd-dlg-mask\"></div>\r\n    <div class=\"vd-dlg-cnt\" style=\"width: {{=config.width || '1000px'}};\" >\r\n        <div class=\"vd-dlg-title\">\r\n            {{=config.title}}\r\n            <div class=\"vd-dlg-close J-vd-dlg-close\">×</div>\r\n        </div>\r\n        <div class=\"vd-dlg-main\">\r\n            {{ if(config.search.length){ }}\r\n            <form class=\"J-vd-search-form\">\r\n                <div class=\"vd-dlg-search-wrap\">\r\n                    {{ $.each(config.search, function(i, item){ }}\r\n                    <div class=\"vd-dlg-search-item {{=item.class}}\">\r\n                        <div class=\"vd-dlg-search-item-label\">\r\n                            {{if(item.type == 'search'){ }}\r\n                            <select name=\"{{=item.searchTypeName}}\" class=\"J-vd-dlg-search-type J-noreset\">\r\n                                {{ $.each(item.options, function(j, option){ }}\r\n                                <option value=\"{{=option.val}}\" data-placeholder=\"{{=option.placeholder}}\">{{=option.txt}}</option>\r\n                                {{ }) }}\r\n                            </select>\r\n                            {{ }else{ }}\r\n                            {{=item.label}}：\r\n                            {{ } }}\r\n                        </div>\r\n                        <div class=\"vd-dlg-search-item-field\">\r\n                            {{ if(item.type == 'select'){ }}\r\n                            <select name=\"{{=item.name}}\">\r\n                                {{ $.each(item.options, function(j, option){ }}\r\n                                <option value=\"{{=option.val}}\">{{=option.txt}}</option>\r\n                                {{ }) }}\r\n                            </select>\r\n                            {{ }else if(item.type == 'radio'){ }}\r\n                            <div class=\"input-radio\">\r\n                                {{ $.each(item.radios, function(j, radio){ }}\r\n                                <label class=\"input-wrap\">\r\n                                    <input type=\"radio\" name=\"{{=item.name}}\" value=\"{{=radio.value}}\">\r\n                                    <span class=\"input-ctnr\"></span>{{=radio.label}}\r\n                                </label>\r\n                                {{ }) }}\r\n                            </div>\r\n                            {{ }else if(item.type == 'search'){ }}\r\n                            <input type=\"text\" class=\"J-vd-dlg-search-input\" name=\"{{=item.inputName}}\">\r\n                            {{ }else if(item.type == 'category'){ }}\r\n                            <select class=\"J-vd-select-lv1\">\r\n                                <option value=\"\">请选择</option>\r\n                                {{ $.each(config.categoryList, function(j, category){ }}\r\n                                <option value=\"{{=category.categoryId}}\">{{=category.categoryName}}</option>\r\n                                {{ }) }}\r\n                            </select>\r\n                            <input type=\"hidden\" class=\"J-vd-dlg-category\" name=\"{{=item.name}}\">\r\n                            {{ }else if(item.type == 'area'){ }}\r\n                            <select class=\"J-vd-area-lv1\" style=\"width: 33%;\" name=\"{{=item.name[0]}}\">\r\n                                <option value=\"\">请选择</option>\r\n                                {{ $.each(item.options, function(j, provice){ }}\r\n                                <option value=\"{{=provice.regionId}}\">{{=provice.regionName}}</option>\r\n                                {{ }) }}\r\n                            </select>\r\n                            <input type=\"hidden\" class=\"J-vd-dlg-category\" name=\"{{=item.name}}\">\r\n                            {{ }else{ }}\r\n                            <input type=\"text\" placeholder=\"{{=item.placeholder}}\" {{if(item.maxlength){ }} maxlength=\"{{=item.maxlength}}\" {{ } }}  name=\"{{=item.name}}\">\r\n                            {{ } }}\r\n                        </div>\r\n                    </div>\r\n                    {{ }) }}\r\n                    <div class=\"vd-dlg-search-btn-wrap\">\r\n                        <div class=\"vd-dlg-btn btn-blue-bd J-vd-dlg-search\">搜索</div>\r\n                        <div class=\"vd-dlg-btn J-vd-dlg-reset\">重置</div>\r\n                    </div>\r\n                </div>\r\n            </form>\r\n            {{ } }}\r\n            <div class=\"vd-dlg-list J-vd-dlg-list-wrap\">\r\n\r\n            </div>\r\n            <div class=\"vd-dlg-loading J-vd-dlg-loading\">加载中。。。</div>\r\n        </div>\r\n        <div class=\"vd-dlg-footer\">\r\n            <div class=\"vd-dlg-btn btn-blue J-vd-dlg-confirm\">选择</div>\r\n        </div>\r\n    </div>\r\n</div>\r\n<!-- ## end ## -->\r\n\r\n<!-- ## list ## -->\r\n{{ if(list.length){ }}\r\n<div class=\"vd-dlg-table-wrap\">\r\n    <table class=\"table\">\r\n        <colgroup>\r\n            <col width=\"100px\">\r\n            {{ $.each(config.listTable, function(i, item){ }}\r\n            <col width=\"{{=item.width}}\">\r\n            {{})}}\r\n        </colgroup>\r\n        <tbody>\r\n            <tr>\r\n                <th>\r\n                    <div class=\"input-checkbox\">\r\n                        <label class=\"input-wrap\">\r\n                            <input type=\"checkbox\" value=\"\" class=\"J-vd-dlg-select-all\">\r\n                            <span class=\"input-ctnr\"></span>全选\r\n                        </label>\r\n                    </div>\r\n                </th>\r\n                {{ $.each(config.listTable, function(i, item){ }}\r\n                <th>{{=item.label}}</th>\r\n                {{})}}\r\n            </tr>\r\n            {{ $.each(list, function(listIndex, listItem){  }}\r\n            <tr>\r\n                <td>\r\n                    <div class=\"input-checkbox\">\r\n                        <label class=\"input-wrap\">\r\n                            <input type=\"checkbox\" {{ if(listItem.selected){ }} checked=\"checked\" {{ } }} {{ if(listItem.disabled){ }} disabled=\"disabled\" {{ } }} data-item='{{=JSON.stringify(listItem)}}' value=\"{{=listItem[config.listId]}}\" class=\"J-vd-dlg-select-item\">\r\n                            <span class=\"input-ctnr\"></span>\r\n                        </label>\r\n                    </div>\r\n                </td>\r\n                {{ $.each(config.listTable, function(i, item){ }}\r\n                <td>{{=listItem[item.name]}}</td>\r\n                {{})}}\r\n            </tr>\r\n            {{})}}\r\n        </tbody>\r\n    </table>\r\n</div>\r\n{{ if(config.needPage){ }}\r\n<div class=\"vd-dlg-pager\">\r\n    <div class=\"vd-dlg-select-info\">\r\n        已选择<span class=\"J-vd-dlg-selected\">12</span>条\r\n    </div>\r\n    <div class=\"J-vd-dlg-pager\"></div>\r\n</div>\r\n{{ } }}\r\n{{ }else{ }}\r\n<div class=\"vd-dlg-list-empty\">\r\n    无结果\r\n</div>\r\n{{ } }}\r\n<!-- ## end ## -->");

    var defaults = {
        title: '标题',
        search: [],
        list: [],
        pageSize: 5,
        searchValid: null,
        needPage: true
    };

    var SearchDialog = function (config) {
        this.config = $.extend({}, defaults, config);
        this.__init();
        return this;
    }

    SearchDialog.prototype = {
        constructor: 'SearchDialog',
        __init: function () {
            var _this = this;
            _this.areaLv1Data = [];
            _this.areaName = [];
            if (this.config.searchLink) {
                $.ajax({
                    url: this.config.searchLink,
                    type: "get",
                    async: false,
                    dataType: "json",
                    success: function (res) {
                        if (res.success) {
                            var resData = res.data;
                            $.each(_this.config.search, function (i, item) {
                                if (item.searchLinkData) {
                                    if (item.searchLinkData.parse) {
                                        resData[item.searchLinkData.key] = item.searchLinkData.parse(resData[item.searchLinkData.key]);
                                    }
                                    _this.config.search[i][item.searchLinkData.value] = resData[item.searchLinkData.key];
                                }

                                if (item.type == 'area') {
                                    _this.areaLv1Data = item.options;
                                    _this.areaName = item.name;
                                }
                            })
                        }
                    }
                })
            }

            $('body').append(tmpl.wrap({
                config: this.config
            }))

            this.$wrapper = $('.J-vd-dlg-wrap');
            this.$list = $('.J-vd-dlg-list-wrap');
            this.prevSearchData = '';
            this.selectedData = $.extend({}, this.config.selectedData);
            this.areaHistoryData = {};
            this.$ajax = null;
            this.refreshList();
            this.__onBind();
        },
        __onBind: function () {
            var _this = this;

            var checkInputPlaceholder = function () {
                var placeholder = $('.J-vd-dlg-search-type', this.$wrapper).find('option:selected').data('placeholder');
                $('.J-vd-dlg-search-input', this.$wrapper).attr('placeholder', placeholder);
            };

            if ($('.J-vd-dlg-search-type', this.$wrapper).length) {
                checkInputPlaceholder();
            }

            $('.J-vd-dlg-search-type', this.$wrapper).click(function () {
                checkInputPlaceholder();
            });

            if ($('.J-vd-dlg-select-all', this.$wrapper).length) {
                _this.__checkSelectAll();
            }

            $('.J-vd-search-form', this.$wrapper).submit(function (e) {
                e.preventDefault();
                return false;
            })

            this.$wrapper.on('change', '.J-vd-dlg-select-item', function () {
                if ($(this)[0].checked) {
                    _this.selectedData[$(this).val()] = $(this).data('item');
                } else {
                    delete _this.selectedData[$(this).val()];
                }
                _this.__setTotalSelected();
                _this.__checkSelectAll();
            })

            this.$wrapper.on('change', '.J-vd-dlg-select-all', function () {
                var $this = $(this);
                $('.J-vd-dlg-select-item', _this.$wrapper).each(function (i, item) {
                    if (!$(this)[0].disabled) {
                        $(this)[0].checked = $this[0].checked;
                        if ($(this)[0].checked) {
                            _this.selectedData[$(this).val()] = $(this).data('item');
                        } else {
                            delete _this.selectedData[$(this).val()];
                        }
                    }
                })
                _this.__setTotalSelected();
            })

            // this.$wrapper.on('click', 'td', function () {
            //     var $checkbox = $(this).find('.J-vd-dlg-select-item');
            //     if ($checkbox.length && !$checkbox[0].disabled) {
            //         $checkbox[0].checked = !$checkbox[0].checked;
            //         _this.__checkSelectAll();
            //     }
            // })

            var setCategoryLv = function (id, lv) {
                var lvData = [];

                $.each(_this.selectLvData, function (i, item) {
                    if (item.categoryId == id && item.nextCayegoryList.length) {
                        lvData = item.nextCayegoryList;
                        if (lv == 1) {
                            _this.selectLvData = item.nextCayegoryList;
                        }
                    }
                })

                if (lvData.length) {
                    $('.J-vd-select-lv' + lv, _this.$wrapper).after('<select class="J-vd-select-lv' + (lv + 1) + '"><option value="">请选择</option></select>');
                    $.each(lvData, function (i, item) {
                        $('.J-vd-select-lv' + (lv + 1), _this.$wrapper).append('<option value="' + item.categoryId + '">' + item.categoryName + '</option>')
                    })
                }
            };

            this.$wrapper.on('change', '.J-vd-select-lv1', function () {
                _this.selectLvData = $.extend({}, _this.config.categoryList);
                $('.J-vd-select-lv2,.J-vd-select-lv3', _this.$wrapper).remove();
                $('.J-vd-dlg-category').val($(this).val() || '');
                setCategoryLv($(this).val(), 1);
            })

            this.$wrapper.on('change', '.J-vd-select-lv2', function () {
                $('.J-vd-select-lv3', _this.$wrapper).remove();
                $('.J-vd-dlg-category').val($(this).val() || $('.J-vd-select-lv1').val());
                setCategoryLv($(this).val(), 2);
            })

            this.$wrapper.on('change', '.J-vd-select-lv3', function () {
                $('.J-vd-dlg-category').val($(this).val() || $('.J-vd-select-lv2').val());
            })

            var setAreaLv = function (id, lv) {
                var lvData = [];

                $.each(_this.areaLvData, function (i, item) {
                    if (item.regionId == id) {
                        if (_this.areaHistoryData[id]) {
                            lvData = _this.areaHistoryData[id];
                        } else {
                            $.ajax({
                                url: _this.config.areaLink,
                                data: {
                                    parentId: id
                                },
                                dataType: 'json',
                                async: false,
                                success: function (res) {
                                    if (res.success) {
                                        lvData = res.data;
                                        _this.areaHistoryData[id] = res.data;
                                    }
                                }
                            })
                        }
                        if (lv == 1) {
                            _this.areaLvData = lvData;
                        }
                    }
                })

                if (lvData.length) {
                    $('.J-vd-area-lv' + lv, _this.$wrapper).after('<select class="J-vd-area-lv' + (lv + 1) + '" name="' + _this.areaName[lv] + '"><option value="">请选择</option></select>');
                    $.each(lvData, function (i, item) {
                        $('.J-vd-area-lv' + (lv + 1), _this.$wrapper).append('<option value="' + item.regionId + '">' + item.regionName + '</option>')
                    })
                }
            };

            this.$wrapper.on('change', '.J-vd-area-lv1', function () {
                _this.areaLvData = _this.areaLv1Data;
                $('.J-vd-area-lv2,.J-vd-area-lv3', _this.$wrapper).remove();

                setAreaLv($(this).val(), 1);
            })

            this.$wrapper.on('change', '.J-vd-area-lv2', function () {
                $('.J-vd-area-lv3', _this.$wrapper).remove();
                setAreaLv($(this).val(), 2);
            })

            $('.J-vd-dlg-search', this.$wrapper).click(function () {
                if (_this.config.searchValid && !_this.config.searchValid()) {
                    return false;
                }

                var data = $('.J-vd-search-form', this.$wrapper).serialize();
                _this.prevSearchData = data;
                _this.refreshList(data);
            })

            $('.J-vd-dlg-reset', this.$wrapper).click(function () {
                var $form = $('.J-vd-search-form', this.$wrapper);

                $form.find('input:text,input:hidden').val('');
                $('select').each(function () {
                    $(this).val($(this).find('option:first').val());
                })
                $form.find('input:radio').prop('checked', false);
                $form.find('.J-vd-select-lv3, .J-vd-select-lv2').remove();

                $('.J-vd-dlg-search', this.$wrapper).click();
            });

            $('.J-vd-dlg-close', this.$wrapper).click(function () {
                _this.close();
            });

            $('.J-vd-dlg-confirm', this.$wrapper).click(function () {
                _this.__confirm();
                _this.close();
            });
        },
        __checkSelectAll: function () {
            var selectFlag = true;
            $('.J-vd-dlg-select-item', this.$wrapper).each(function (i, item) {
                if (!$(this)[0].disabled && !$(this)[0].checked) {
                    selectFlag = false;
                }
            })

            $('.J-vd-dlg-select-all', this.$wrapper).length && ($('.J-vd-dlg-select-all', this.$wrapper)[0].checked = selectFlag);
        },
        refreshList: function (data, pageNum) {
            data = data ? data.split('&') : [];
            data.push('pageSize=' + this.config.pageSize);
            if (this.config.listDefaultData) {
                data = data.concat(this.config.listDefaultData);
            }
            data = data.join('&')
            var _this = this;
            _this.$list.empty();
            _this.$wrapper.find('.J-vd-dlg-loading').show();

            if (pageNum) {
                data += '&pageNum=' + pageNum;
            }

            var searchData = {};

            $.each(data.split('&'), function (i, searchItem) {
                var item = searchItem.split('=');

                if (_this.config.searchParams && _this.config.searchParams[item[0]]) {
                    searchData[_this.config.searchParams[item[0]]] = item[1]
                } else {
                    searchData[item[0]] = item[1];
                }
            })

            if (this.config.listLinkMethod == 'post') {
                searchData = JSON.stringify(searchData);
            }

            this.$ajax && this.$ajax.abort();
            this.$ajax = $.ajax({
                url: this.config.listLink,
                data: searchData,
                type: this.config.listLinkMethod || 'get',
                dataType: 'json',
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function (res) {
                    if (res && res.success) {
                        var resData = res.data;

                        if (_this.config.listDataParse) {
                            resData = _this.config.listDataParse(res.data);
                        }

                        var list = resData.list;

                        $.each(list, function (i, item) {
                            if (_this.config.selectedData[item[_this.config.listId]]) {
                                list[i].selected = true;
                                list[i].disabled = true;
                            }

                            if (_this.selectedData[item[_this.config.listId]]) {
                                list[i].selected = true;
                            }
                        });

                        _this.$list.append(tmpl.list({
                            config: _this.config,
                            list: list
                        }))

                        _this.__checkSelectAll();

                        if (_this.config.needPage && resData.page.total > _this.config.pageSize) {
                            new Pager({
                                el: $('.J-vd-dlg-pager', _this.$wrapper),
                                pageNum: pageNum || 1,
                                total: resData.page.total,
                                pageSize: _this.config.pageSize,
                                needJump: false,
                                callback: function (num) {
                                    var searchData = _this.prevSearchData;
                                    _this.refreshList(searchData, num);
                                }
                            })
                        }

                    }

                    _this.$wrapper.find('.J-vd-dlg-loading').hide();
                    _this.__setTotalSelected();
                }
            })
        },
        __setTotalSelected: function () {
            $('.J-vd-dlg-selected', this.$wrapper).html(Object.keys(this.selectedData).length);
        },
        __confirm: function () {
            this.config.confirm && this.config.confirm(this.selectedData);
        },
        close: function () {
            this.$wrapper.remove();
        }
    }

    window.SearchDialog = SearchDialog;

}.call(this);